package checkers.client.run;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

import checkers.common.logic.classes.CheckersPosition;

public class MainForm {
	
	private JFrame mainFrame = new JFrame("Checkers");
	private Container mainCont = mainFrame.getContentPane();
	private final int sizeX = 8;
	private final int sizeY = 8;
	
	private CheckersButton[][] buttons = new CheckersButton[sizeX][sizeY];
	
	public void paintFrame() {
		mainCont.setFocusable(true);
		mainFrame.setSize(sizeX * 60, sizeY * 60);
		mainFrame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		mainCont.setLayout(new GridLayout(sizeY, sizeX));
		mainFrame.setVisible(true);
		for (int y = 0; y < sizeY; y++) {
			for (int x = 0; x < sizeX; x++) {
				buttons[x][sizeY - y - 1] = new CheckersButton(x, sizeY - y - 1);
				mainCont.add(buttons[x][sizeY - y - 1]);
			}
		}
	}
	
	public void updateCheckers() {
		for (int x = 0; x < sizeX; x++)
			for (int y = 0; y < sizeY; y++) {
				int[][] board = CheckersPosition.defaultPositions;
				buttons[x][y].set(board[x][y]);
			}
	}

}
